//
//  LPActivityDetailDetailsHeaderView.m
//  LovingPartyBuilding
//
//  Created by 刘应平 on 2017/6/8.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "LPActivityDetailDetailsHeaderView.h"

@interface LPActivityDetailDetailsHeaderView ()
/**  model  */
@property (strong, nonatomic) LPActivityDetailInforModel  *model;
/**  背景图  */
@property (strong, nonatomic) UIImageView  *backImageView;
/**  参与人数  */
@property (strong, nonatomic) UILabel  *numberLabel;
/**  共享人数  */
@property (strong, nonatomic) UILabel  *shareNumberLabel;
/**  分割线  */
@property (strong, nonatomic) UIView  *centreView;
/**  标题  */
@property (strong, nonatomic) UILabel  *headLineLabel;
/**  内容  */
@property (strong, nonatomic) UILabel  *contentLabel;
/**  地址  */
@property (strong, nonatomic) UILabel  *addressLabel;
/**  地址图片  */
@property (strong, nonatomic) UIImageView  *addressImageView;
/**  时间  */
@property (strong, nonatomic) UILabel  *timeLabel;
/**  时间图片  */
@property (strong, nonatomic) UIImageView  *timeImageView;
/**  主办单位  */
@property (strong, nonatomic) UILabel  *hostLabel;
/**  主办单位图片  */
@property (strong, nonatomic) UIImageView  *hostImageView;

@end
@implementation LPActivityDetailDetailsHeaderView

- (instancetype)initWithFrame:(CGRect)frame inforModel:(LPActivityDetailInforModel *)model
{
    self = [super initWithFrame:frame];
    if (self) {
        self.model = model;
        [self layoutUI];
        [self fuzhi];
    }
    return self;
}


/**  195  */
#pragma mark - 界面
- (void)layoutUI{
    [self addSubview:self.backImageView];
    [self.backImageView addSubview:self.numberLabel];
//    [self.backImageView addSubview:self.shareNumberLabel];
    [self addSubview:self.centreView];
    [self addSubview:self.headLineLabel];
    [self addSubview:self.contentLabel];
    [self addSubview:self.hostImageView];
    [self addSubview:self.hostLabel];
    [self addSubview:self.timeImageView];
    [self addSubview:self.timeLabel];
    [self addSubview:self.addressImageView];
    [self addSubview:self.addressLabel];
    self.backImageView.sd_layout
    .topEqualToView(self)
    .leftEqualToView(self)
    .rightEqualToView(self)
    .heightIs(0.6 *  [UIScreen zj_screenWith]);
    
    
    
    self.numberLabel.sd_layout
    .bottomSpaceToView(self.backImageView, 15 * [UIScreen zj_screenHScale])
    .widthIs(100 * [UIScreen zj_screenWScale])
    .rightSpaceToView(self.backImageView, 20 * [UIScreen zj_screenWScale])
    .heightIs(35 * [UIScreen zj_screenHScale]);
    
    self.shareNumberLabel.sd_layout
    .bottomSpaceToView(self.numberLabel, 10 * [UIScreen zj_screenHScale])
    .widthIs(100 * [UIScreen zj_screenWScale])
    .rightSpaceToView(self.backImageView, 20 * [UIScreen zj_screenWScale])
    .heightIs(35 * [UIScreen zj_screenHScale]);

    
    self.centreView.sd_layout
    .topSpaceToView(self.backImageView, 10 * [UIScreen zj_screenHScale])
    .widthIs([UIScreen zj_screenWith])
    .leftEqualToView(self.backImageView)
    .heightIs(1);
    
    
    self.headLineLabel.sd_layout
    .topSpaceToView(self.centreView, 20 * [UIScreen zj_screenHScale])
    .widthIs([UIScreen zj_screenWith] - 20 * [UIScreen zj_screenWScale])
    .leftSpaceToView(self, 10 * [UIScreen zj_screenWScale])
    .heightIs(self.model.NAMEHEIGHT);
    
    self.contentLabel.sd_layout
    .topSpaceToView(self.headLineLabel, 10 * [UIScreen zj_screenHScale])
    .widthIs([UIScreen zj_screenWith] - 20 * [UIScreen zj_screenWScale])
    .leftSpaceToView(self, 10 * [UIScreen zj_screenWScale])
    .heightIs(self.model.HEIGHT);
    
    self.hostImageView.sd_layout
    .topSpaceToView(self.contentLabel, 20 * [UIScreen zj_screenHScale])
    .widthIs(13 * [UIScreen zj_screenHScale])
    .leftSpaceToView(self, 15 * [UIScreen zj_screenWScale])
    .heightIs(13 * [UIScreen zj_screenHScale]);
    
    self.hostLabel.sd_layout
    .topEqualToView(self.hostImageView)
    .widthIs([UIScreen zj_screenWith] - 35 * [UIScreen zj_screenWScale] - 13 * [UIScreen zj_screenHScale])
    .leftSpaceToView(self.hostImageView, 10 * [UIScreen zj_screenWScale])
    .heightIs(13 * [UIScreen zj_screenHScale]);
    
    self.timeImageView.sd_layout
    .topSpaceToView(self.hostImageView, 15 * [UIScreen zj_screenHScale])
    .widthIs(13 * [UIScreen zj_screenHScale])
    .leftSpaceToView(self, 15 * [UIScreen zj_screenWScale])
    .heightIs(13 * [UIScreen zj_screenHScale]);
    
    self.timeLabel.sd_layout
    .topEqualToView(self.timeImageView)
    .widthIs([UIScreen zj_screenWith] - 35 * [UIScreen zj_screenWScale] - 13 * [UIScreen zj_screenHScale])
    .leftSpaceToView(self.timeImageView, 10 * [UIScreen zj_screenWScale])
    .heightIs(13 * [UIScreen zj_screenHScale]);
    
    self.addressImageView.sd_layout
    .topSpaceToView(self.timeImageView, 10 * [UIScreen zj_screenHScale])
    .widthIs(13 * [UIScreen zj_screenHScale])
    .leftSpaceToView(self, 15 * [UIScreen zj_screenWScale])
    .heightIs(13 * [UIScreen zj_screenHScale]);
    
    self.addressLabel.sd_layout
    .topEqualToView(self.addressImageView)
    .widthIs([UIScreen zj_screenWith] - 35 * [UIScreen zj_screenWScale] - 13 * [UIScreen zj_screenHScale])
    .leftSpaceToView(self.addressImageView, 10 * [UIScreen zj_screenWScale])
    .heightIs(13 * [UIScreen zj_screenHScale]);
    
    
}


#pragma mark - 私有方法
- (void)fuzhi{
    NSString *urlString;
    if (self.model.COVER_JSON.count == 0) {
        urlString = @"sda";
    }else{
        urlString = self.model.COVER_JSON[0][@"file_path"];
    }
    [self.backImageView sd_setImageWithURL:CREATEURL(urlString) placeholderImage:PlaceholderHUODONGBIGImage];
    NSString *numberString;
    NSString *number;
    if (self.model.ENROLL_NUM.length == 0) {
        number = @"0";
        numberString = @"参与人数: 0";
    }else{
        number = self.model.ENROLL_NUM;
        numberString = [NSString stringWithFormat:@"参与人数: %@",self.model.ENROLL_NUM];
    }
    
    NSMutableAttributedString *joinString = [[NSMutableAttributedString alloc] initWithString:numberString];
    [joinString setAttributes:@{NSForegroundColorAttributeName: [UIColor zj_colorWithHexString:@"f24141"]} range:[numberString rangeOfString:number]];
    self.numberLabel.attributedText = joinString;
    
    
    NSString *numberStringshare;
    NSString *numberShare;
    if (self.model.SHARE_NUM.length == 0) {
        numberShare = @"0";
        numberStringshare = @"共享人数: 0";
    }else{
        numberShare = self.model.SHARE_NUM;
        numberStringshare = [NSString stringWithFormat:@"共享人数: %@",self.model.SHARE_NUM];
    }
    
    NSMutableAttributedString *shareString = [[NSMutableAttributedString alloc] initWithString:numberStringshare];
    [shareString setAttributes:@{NSForegroundColorAttributeName: [UIColor zj_colorWithHexString:@"f24141"]} range:[numberStringshare rangeOfString:numberShare]];
    self.shareNumberLabel.attributedText = shareString;

    
   
    
    
    self.headLineLabel.attributedText = [UILabel setSpaceForLineWithText:self.model.NAME lineSpace:3 * [UIScreen zj_screenHScale]];
    self.contentLabel.attributedText = [UILabel setSpaceForLineWithText:self.model.DESCRIPTION lineSpace:4 * [UIScreen zj_screenHScale]];
    if (self.model.SPONSOR.length == 0) {
        self.hostLabel.text = @"暂无";
    }else{
        self.hostLabel.text = self.model.SPONSOR;
    }
    
    if (self.model.START_TIME.length == 0) {
        self.timeLabel.text = @"待定";
    }else{
        self.timeLabel.text =[NSDateFormatter stringMonthAndHourAndMintueWithDate:self.model.START_TIME];
    }
    
    if (self.model.ADDRESS.length == 0) {
        self.addressLabel.text = @"暂无";
    }else{
        self.addressLabel.text = self.model.ADDRESS;
    }
    
}

- (void)setAddNumber:(BOOL)addNumber{
    _addNumber = addNumber;
    NSString *numberString;
    NSString *number;
    if (self.model.ENROLL_NUM.length == 0) {
        number = @"1";
        numberString = @"参与人数: 1";
    }else{
        number = [NSString stringWithFormat:@"%ld",[self.model.ENROLL_NUM integerValue] + 1] ;
        numberString = [NSString stringWithFormat:@"参与人数: %@",number];
    }
    
    NSMutableAttributedString *joinString = [[NSMutableAttributedString alloc] initWithString:numberString];
    [joinString setAttributes:@{NSForegroundColorAttributeName: [UIColor zj_colorWithHexString:@"f24141"]} range:[numberString rangeOfString:number]];
    self.numberLabel.attributedText = joinString;
}


- (void)tapNumber:(UITapGestureRecognizer *)tap{

    if (self.delegate) {
        [self.delegate LPActivityDetailDetailsHeaderViewTap_canYu_tapIndex:tap.view.tag];
    }
    
}

#pragma mark - getter
- (UIImageView *)backImageView{
    if (_backImageView == nil) {
        _backImageView = [UIImageView new];
        _backImageView.userInteractionEnabled = YES;
        _backImageView.contentMode = UIViewContentModeScaleAspectFill;
        _backImageView.clipsToBounds = YES;
    }
    return _backImageView;
}
- (UIImageView *)addressImageView{
    if (_addressImageView == nil) {
        _addressImageView = [UIImageView new];
        _addressImageView.contentMode = UIViewContentModeCenter;
        _addressImageView.image = [UIImage imageNamed:@"hdxq_address"];
    }
    return _addressImageView;
}
- (UIImageView *)timeImageView{
    if (_timeImageView == nil) {
        _timeImageView = [UIImageView new];
        _timeImageView.contentMode = UIViewContentModeCenter;
        _timeImageView.image = [UIImage imageNamed:@"hdxq_time"];
    }
    return _timeImageView;
}
- (UIImageView *)hostImageView{
    if (_hostImageView == nil) {
        _hostImageView = [UIImageView new];
        _hostImageView.contentMode = UIViewContentModeCenter;
        _hostImageView.image = [UIImage imageNamed:@"hdxq_street"];
    }
    return _hostImageView;
}

- (UILabel *)numberLabel{
    if (!_numberLabel) {
        _numberLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentCenter;
            label.textColor = [UIColor textBlackColor];
            label.backgroundColor = [UIColor whiteColor];
            label.layer.cornerRadius = 10;
            label.layer.masksToBounds = YES;
            label.tag = 1;
            label.font = [UIFont systemFontOfSize:15 * [UIScreen zj_textFontScale]];
            label.userInteractionEnabled = YES;
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapNumber:)];
            [label addGestureRecognizer:tap];
            label;
        });
    }
    return _numberLabel;
}

- (UILabel *)shareNumberLabel{
    if (!_shareNumberLabel) {
        _shareNumberLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentCenter;
            label.textColor = [UIColor textBlackColor];
            label.backgroundColor = [UIColor whiteColor];
            label.layer.cornerRadius = 10;
            label.layer.masksToBounds = YES;
            label.tag = 2;
            label.font = [UIFont systemFontOfSize:15 * [UIScreen zj_textFontScale]];
            label.userInteractionEnabled = YES;
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapNumber:)];
            [label addGestureRecognizer:tap];
            label;
        });
    }
    return _shareNumberLabel;
}


- (UILabel *)headLineLabel{
    if (!_headLineLabel) {
        _headLineLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentCenter;
            label.textColor = [UIColor textBlackColor];
            label.numberOfLines = 0;
            label.backgroundColor = [UIColor clearColor];
            label.font = [UIFont systemFontOfSize:16 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _headLineLabel;
}

- (UILabel *)contentLabel{
    if (!_contentLabel) {
        _contentLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.numberOfLines = 0;
            label.textColor = [UIColor textBlackColor];
            label.font = [UIFont systemFontOfSize:15 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _contentLabel;
}

- (UILabel *)hostLabel{
    if (!_hostLabel) {
        _hostLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor lightGrayColor];
            label.font = [UIFont systemFontOfSize:14 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _hostLabel;
}

- (UILabel *)timeLabel{
    if (!_timeLabel) {
        _timeLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor lightGrayColor];
            label.font = [UIFont systemFontOfSize:14 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _timeLabel;
}

- (UILabel *)addressLabel{
    if (!_addressLabel) {
        _addressLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor lightGrayColor];
            label.font = [UIFont systemFontOfSize:14 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _addressLabel;
}

- (UIView *)centreView{
    if (!_centreView) {
        _centreView = [UIView new];
        _centreView.backgroundColor = [UIColor lightGrayColor];
    }
    return _centreView;
    
}

@end
